/*
#
#  Copyright 2011 Matthew Jannace
#
#  This file is part of RoboCode BlackHoleAgent
#
#  RoboCode BlackHoleAgent is free software: you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation, either version 3 of the
#  License, or (at your option) any later version.
#
#  RoboCode BlackHoleAgent is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with RoboCode BlackHoleAgent. If not, see
#  <http://www.gnu.org/licenses/>.
#
 */
package com.jannaceltd.TeamBlackHoleBeer.Modules.HelperClasses;

import com.jannaceltd.TeamBlackHoleBeer.Utilities.MathUtils;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.io.Serializable;

/**
 * Class to store Virtual Bullet Information
 * @author Matthew Jannace <mjannace@gmail.com>
 * @version 1.0
 */
public class VirtualBullets implements Serializable {

    private static final long serialVersionUID = 5890963822395906392L;
    /**
     * Bullet Name/ID
     */
    protected String Name;
    /**
     * Bullet XY position when Fired
     */
    protected Point2D.Double fireSourceLocation;
    /**
     * Time Bullet was fired
     */
    protected long fireTime;
    /**
     * Power of the Bullet
     */
    protected double firePower;
    /**
     * Bullet Velocity
     */
    protected double bulletVelocity;
    /**
     * Bullet Heading
     */
    protected double HeadingRadians;

    /**
     * Creates a Virtual Bullet Object
     */
    public VirtualBullets() {
        this.Name = "";
        this.fireSourceLocation = new Point2D.Double();
        this.fireTime = 0L;
        this.firePower = 0d;
        this.bulletVelocity = 0d;
        this.HeadingRadians = 0d;
    }

    /**
     * Creates a Virtual Bullet Object
     * @param vb
     */
    public VirtualBullets(VirtualBullets vb) {
        this.Name = vb.getName();
        this.fireSourceLocation = vb.getSourceLocation();
        this.fireTime = vb.getFireTime();
        this.firePower = vb.getPower();
        this.bulletVelocity = vb.getVelocity();
        this.HeadingRadians = vb.getHeadingRadians();
    }

    /**
     * Creates a Virtual Bullet Object
     * @param Name
     * @param fireSourceLocation
     * @param fireTime
     * @param firePower
     * @param bulletVelocity
     * @param absAngle 
     */
    public VirtualBullets(String Name,
            Point2D.Double fireSourceLocation,
            long fireTime,
            double firePower,
            double bulletVelocity,
            double absAngle) {
        this.Name = Name;
        this.fireSourceLocation = fireSourceLocation;
        this.fireTime = fireTime;
        this.firePower = firePower;
        this.bulletVelocity = bulletVelocity;
        this.HeadingRadians = absAngle;
    }

    /**
     * Gets the Name of the Bullet
     * @return Name
     */
    public String getName() {
        return Name;
    }

    /**
     * Sets the Name of the Bullet
     * @param Name
     */
    public void setName(String Name) {
        this.Name = Name;
    }

    /**
     * Gets the current heading of the Bullet in Radians
     * @return HeadingRadians
     */
    public double getHeadingRadians() {
        return HeadingRadians;
    }

    /**
     * Sets the current heading of the Bullet in Radians
     * @param absAngle
     */
    public void setHeadingRadians(double absAngle) {
        this.HeadingRadians = absAngle;
    }

    /**
     * Gets the current Velocity of the Bullet
     * @return bulletVelocity
     */
    public double getVelocity() {
        return bulletVelocity;
    }

    /**
     * Sets the current Velocity of the Robot
     * @param bulletVelocity
     */
    public void setVelocity(double bulletVelocity) {
        this.bulletVelocity = bulletVelocity;
    }

    /**
     * Gets the fire Power of the Bullet
     * @return firePower
     */
    public double getPower() {
        return firePower;
    }

    /**
     * Sets the fire Power of the Bullet
     * @param firePower
     */
    public void setPower(double firePower) {
        this.firePower = firePower;
    }

    /**
     * Gets the Source Location of the Bullet
     * @return fireSourceLocation
     */
    public Double getSourceLocation() {
        return fireSourceLocation;
    }

    /**
     * Sets the Source Location of the Bullet
     * @param fireSourceLocation 
     */
    public void setSourceLocation(Double fireSourceLocation) {
        this.fireSourceLocation = fireSourceLocation;
    }

    /**
     * Gets the time when the Bullet was fired
     * @return fireTime
     */
    public long getFireTime() {
        return fireTime;
    }

    /**
     * Sets the time when the Bullet was fired
     * @param fireTime
     */
    public void setFireTime(long fireTime) {
        this.fireTime = fireTime;
    }

    /**
     * Gets the location of the bullet at the time of the parameter
     * @param currentTime
     * @return bulletLocation
     */
    public Point2D.Double getBulletPosition(Long currentTime) {
        // if the distance from the wave origin to our enemy has passed
        // the distance the bullet would have traveled...
        return MathUtils.project(fireSourceLocation, HeadingRadians, (currentTime - fireTime) * bulletVelocity);
    }

    /**
     * Determines if the Bullet has gone past the enemy
     * @param myPos
     * @param enemyPos
     * @param currentTime
     * @return True if Bullet is still in flight else False
     */
    public boolean checkBulletStillInFlight(Point2D.Double myPos, Point2D.Double enemyPos, long currentTime) {
        // if the distance from the wave origin to our enemy has passed
        // the distance the bullet would have traveled...
        if (myPos.distance(enemyPos) <= (currentTime - fireTime) * MathUtils.bulletVelocity(firePower)) {
            return true;
        }
        return false;
    }
}
